// $codepro.audit.disable
/**
 * package for all the model classes to fit the mvc format
 */
package javamonsters.model;

import java.util.Random;

/**
 * Class dealing with random encounters while traveling
 * @author John
 * @version 1.0
 *
 */
public class Encounter {
	
	/**
	 * random object
	 */
	private static final Random RAND = new Random();
	
	/**
	 * the type of encounter
	 */
	private final Encounters encounterType;
	
	/**
	 * encounter constructor
	 */
	public Encounter() {
		
		encounterType = Encounters.chooseEncounter();
	}
	
	public enum Encounters {
		PIRATE,
		POLICE,
		WRECK,
		GOVT;
		
		/**
		 * @return returns the type of encounter
		 */
		private static final Encounters chooseEncounter() {
			return Encounters.values()[RAND.nextInt(Encounters.values().length)];
		}
	}
	
	/**
	 * @return String representation of Encounter
	 */
	public String toString() {
		return "encounter";
	}
	
	/**
	 * @return returns a string explaining what happened in the encounter
	 */
	public String randEncounter() {
		String ret = null;
		
		switch(encounterType) {
			case PIRATE:
				ret = "A pirate has stolen 100 credits from you!";
				break;
			case POLICE:
				ret = "The space police have conducted a search of your cargo" +
					  " and fined you 100 credits!";
				break;
			case WRECK:
				ret = "You stumbled upon a deserted ship wreck and found 100 credits!";
				break;
			case GOVT:
				ret = "Because of a tax refund, the government has rewarded" +
					  " you 100 credits!";
				break;
			default: ret = "default";
		}
			
		return ret;
	}
	
	/**
	 * @return returns a boolean which determines whether or not an encounter occurs
	 */
	public boolean hasEncounter() {
		final int sampleSize = 10;
		final int thirtyPercent = 3;
		final int chance = RAND.nextInt(sampleSize);
		
		return (chance < thirtyPercent);
		
	}
	
	/**
	 * @return returns the type of the encounter
	 */
	public Encounters getEncounterType() {
		return encounterType;
	}
}
